home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-03-20 | 2.6 KB | 82 lines | [TEXT/ttxt] |
- // © Copyright 1994 Apple Computer, Inc, All Rights Reserved
-
- // Basic constants that we may or may not need
- constant kAppName := '|SerialEx:PIEDTS|;
- constant kAppSymbol := '|SerialEx:PIEDTS|;
-
-
- // This is our protoEndpoint specification. Note we are
- // using DefConst so the symbol is known as a constant when
- // we compile the proto, and later use it during runtime.
-
- DefConst('protoLlamaPEndpoint, {
- // basic endpoint proto
- _proto: protoEndpoint,
-
- // Options (array stored inside the configOptions slot.
- configOptions: [
- // basic serial port
- { label: kCMSAsyncSerial, type: 'service, opCode: opSetRequired },
- // basic serial port options
- { label: kCMOSerialIOParms, type: 'option, opCode: opSetNegotiate,
- data: { bps: k9600bps, dataBits: k8DataBits, stopBits: k1StopBits,
- parity: kNoParity } },
- // flow control (XON/XOFF)
- { label: kCMOInputFlowControlParms, type: 'option, opCode: opSetNegotiate,
- data: { xonChar: unicodeDC1, xoffChar: unicodeDC3, useSoftFlowControl: true,
- useHardFlowControl: nil } },
- ],
-
- // Our exception handler (asynch exceptions from the endpoint).
- exceptionHandler: func(exception)
- begin
- print("Got the exception from Abort, ignoring it for the time being");
- end,
-
- // Our state machines:
- // WaitForAck, main dispatcher, waits for the first ACK from the other side.
- waitForACK:
- {
- InputForm: 'string,
- endCharacter: $?, // ACK? expected
- discardAfter: 200, // scan buffer size
-
- InputScript: func(endpoint, s)
- begin
- if (StrPos(s, "ACK?", 0)) then // send response (help instructions in this case)
- begin
- endpoint:Output("Send any of the following commands:" & unicodeCR &
- unicodeLF, nil);
- endpoint:Output("PLAY! -- will play a tone on the Newton" & unicodeCR &
- unicodeLF, nil);
- endpoint:Output("Add more comments if more functions...." & unicodeCR &
- unicodeLF, nil);
- endpoint:FlushOutput();
- endpoint:SetInputSpec(endpoint.waitForFUNCTION); // the main dispatch loop
- end
- end,
- },
-
-
- // This is the generic dispatcher state, send something ending with ! and
- // the Newton will serve.
- waitForFUNCTION:
- {
- InputForm: 'string,
- endCharacter: $!, // expects a '!' as part of the command
- discardAfter: 200, // scan buffer size
-
- InputScript: func(endpoint, s)
- begin
- if(StrPos(s, "PLAY!", 0)) then // play function
- begin
- PlaySound(ROM_funbeep);
- endpoint:Output(unicodeCR, nil);
- endpoint:Output(unicodeLF, nil);
- endpoint:FlushOutput();
- end;
- end;
- },
- });
-
-